import { createRouter, createWebHashHistory } from 'vue-router'

// 公共布局(父路由一级)
const Layout = () => import('@/views/Layout')
// 子路由二级
// 首页
const Home = () => import('@/views/Home')
// 商品详情
const Detail = () => import('@/views/Goods')
// 购物车
const Cart = () => import('@/views/Cart')
// 下单
const Order = () => import('@/views/Member/settlement')
// 支付
const Pay = () => import('@/views/Member/pay')
// 支付结果
const PayResult = () => import('@/views/Member/pay/result')

// 登录(一级路由)
const Login = () => import('@/views/Login')

// 路由配置规则
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      {
        path: '/good/:id',
        component: Detail
      },
      {
        path: '/cart',
        component: Cart
      },
      {
        path: '/order',
        component: Order
      }, {
        path: '/pay',
        component: Pay
      },
      { path: '/pay/callback', component: PayResult }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 每次路由跳转重置滚动条位置
  scrollBehavior () {
    // vue2: {x:0,y:0} | vue3: {left: 0, top: 0}
    return { left: 0, top: 0 }
  }
})

export default router
